<route>
{
  "meta":{
    "title":"主题设置",
    "showMenu" :true,
    "envHide":"DESINGER,PREVIEW,PORTAL",
    "serialNum": 55,
    "localism": "sys.theme_setting"
  }
}
</route>
<template>
  <div>
    <div class="theme-setting">
      <h3 class="theme-setting__title">{{ $t("sys.theme_color") }}</h3>
      <div class="theme-setting__setting theme-setting__theme">
        <div
          class="theme-setting__setting--item theme-setting__theme--color"
          v-for="color in THEME_COLOR_ENUM"
          :key="color"
          :style="{ background: color }"
          @click="handleThemeChange(color)"
        >
          <div v-show="currentColor === color" class="theme-setting__active">
            <IconPark type="check-small" size="18" fill="#fff"></IconPark>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { IconPark } from "@icon-park/vue/es/all";
import ThemeUtil, { THEME_COLOR_ENUM, DEFAULT_THEME_COLOR } from "@/theme";
export default {
  name: "ThemeSetting",
  components: {
    IconPark,
  },
  data() {
    return {
      THEME_COLOR_ENUM,
      currentColor: "",
    };
  },

  created() {},

  mounted() {
    this.init();
  },

  methods: {
    init() {
      this.currentColor = ThemeUtil.getColor() || DEFAULT_THEME_COLOR;
    },
    handleThemeChange(color) {
      ThemeUtil.setColor(color);
      this.currentColor = color;
    },
  },
};
</script>

<style lang="scss" scoped>
.theme-setting {
  padding: 10px 0;

  &__title {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
  }

  &__setting {
    margin-top: 20px;
    // padding: 0 10px;
  }

  &__theme {
    display: flex;

    &--color {
      width: 36px;
      height: 36px;
      border-radius: 5px;
      margin-right: 40px;
      cursor: pointer;
      overflow: hidden;
      position: relative;
    }
  }

  &__active {
    height: 20px;
    width: 20px;
    position: absolute;
    // right: 0;
    // bottom: 0;
    right: 50%;
    bottom: 50%;
    transform: translate(50%, 50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
  }
}
</style>
